<?php

namespace App\Models\Product;

use Illuminate\Database\Eloquent\Model;
use App\Models\Config as ConfigModel;

class OrderProduct extends Model
{

    protected $table = 'order_product';

    protected $dateFormat = 'U';

    const CREATED_AT = null;

    const UPDATED_AT = 'updatetime';

    protected $guarded = [];

    protected $appends = [
        'proimg_list', //评价多张图
    ];
      /**
     * 修改时间格式
     */
    protected $casts = [
        'updatetime' => 'datetime:Y-m-d H:i:s',
    ];
    public function product()
    {
        return $this->belongsTo('App\Models\Product\Product', 'proid', 'id');
    }
    public function business()
    {
        return $this->belongsTo('App\Models\Business\Business', 'busid', 'id');
    }
    public function getProimgListAttribute()
    {

        $urls = ConfigModel::where('name', 'shourl')->value('value');

        $url = env('SITE_URL', $urls);

        $proimg_text = '';

        $proimgs = !empty($this->attributes['proimg']) ?  $this->attributes['proimg']: [];

        if(!empty($proimgs))
        {
            $proimgs = str_ireplace("/uploads/", $url. "/uploads/",$proimgs);
            $proimg_text = explode(',', $proimgs);

        }
        return $proimg_text;
    }
}